﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ePioneer_ep_lecturer_edit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            CMSModel.CMSEntities dal = DAL.DBManager.GetCmsEmtity();
            if (Request["id"] != null)
            {
                int id = int.Parse(Request["id"].ToString());

                CMSModel.ePioneer_Lecturer m_epl = dal.ePioneer_Lecturer.First(x => x.Id == id);

                txt_Lecturer.Text = m_epl.Lecturer;
                txt_BriefInfo.Text = m_epl.BriefInfo;
                Image1.ImageUrl = m_epl.PicUrl;
            }
        }
    }
    protected void BtnModify_Click(object sender, EventArgs e)
    {
        string imgPath = System.Configuration.ConfigurationManager.AppSettings["imgPath"].ToString();      //imgpath
        string filePath = System.Configuration.ConfigurationManager.AppSettings["filePath"].ToString();       //filepath
        if (Request["id"] != null)
        {
            try
            {
                int id = int.Parse(Request["id"].ToString());
                CMSModel.CMSEntities dal = DAL.DBManager.GetCmsEmtity();
                CMSModel.ePioneer_Lecturer m_epl = dal.ePioneer_Lecturer.First(x => x.Id == id);
                m_epl.Lecturer = txt_Lecturer.Text;
                m_epl.BriefInfo = txt_BriefInfo.Text;
                if (flImg.FileBytes.Length > 0)
                {
                    var data = flImg.FileBytes;
                    string msg = "";
                    string path = filePath + "pioneer/" + flImg.FileName;

                    string strImgPath = imgPath + "pioneer/" + flImg.FileName;
                    m_epl.PicUrl = strImgPath;
                    Deliver.AsynchronousClient.StartTranCommand(data, path, out msg);
                }
                dal.SaveChanges();
                ClientScript.RegisterStartupScript(GetType(), "aa", "alert('修改成功');document.location='ep_lecturer.aspx'", true);
            }
            catch (Exception)
            {
                ClientScript.RegisterStartupScript(GetType(), "aa", "alert('修改失败');", true);
            }
        }
        else
        {
            CMSModel.CMSEntities dal = DAL.DBManager.GetCmsEmtity();
            CMSModel.ePioneer_Lecturer m_epl =new CMSModel.ePioneer_Lecturer();
            m_epl.Lecturer = txt_Lecturer.Text;
            m_epl.BriefInfo = txt_BriefInfo.Text;
            if (flImg.FileBytes.Length > 0)
            {
                var data = flImg.FileBytes;
                string msg = "";
                string path = filePath + "pioneer/" + flImg.FileName;
                string strImgPath = imgPath + "pioneer/" + flImg.FileName;
                m_epl.PicUrl = strImgPath;
                Deliver.AsynchronousClient.StartTranCommand(data, path, out msg);
            }
            try
            {
                dal.AddToePioneer_Lecturer(m_epl);
                dal.SaveChanges();
                ClientScript.RegisterStartupScript(GetType(), "aa", "alert('添加成功');document.location='ep_lecturer.aspx'", true);
            }
            catch (Exception)
            {

                ClientScript.RegisterStartupScript(GetType(), "aa", "alert('添加失败');", true);
            }
        }
    }
}